<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:asp="http://southchina-logistics.com/nywl/asp"  xmlns:uc1="http://southchina-logistics.com/uc1" xmlns:dxwtl="http://southchina-logistics.com/dxwtl" xmlns:dxcp="http://southchina-logistics.com/dxcp" xmlns:dxp="http://southchina-logistics.com/dxp" xmlns:dxe="http://southchina-logistics.com/dxe" xmlns:dxwgv="http://southchina-logistics.com/dxwgv">
<xsl:output method="xml" version="1.0" encoding="gb2312" indent="yes"/>

<!-- 产生字段的列 -->
<xsl:template name="PropertyColumn">

<xsl:variable name="FieldName" select="Name"></xsl:variable>
<xsl:variable name="DbType" select="DbType"></xsl:variable>
<xsl:variable name="IsEnum" select="IsEnum"></xsl:variable>
<xsl:variable name="EnumType" select="EnumType"></xsl:variable>
<xsl:variable name="IsKey" select="IsKey"></xsl:variable>
<xsl:variable name="IsForigenKey" select="IsForigenKey"></xsl:variable>
<xsl:variable name="IsAssociation" select="IsAssociation"></xsl:variable>
<xsl:variable name="ColumnShow" select="UIMetaInfo/ColumnShow"></xsl:variable>
<xsl:variable name="MasterTable" select="MasterTable"></xsl:variable>
<xsl:variable name="MasterField" select="MasterField"></xsl:variable>

<!-- 根据DbType决定DataType的类型 -->
<xsl:variable name="DataType" >
<xsl:choose>
	<xsl:when test="$DbType='BigInt'">number</xsl:when>
	<xsl:when test="$DbType='Int'">number</xsl:when>
	<xsl:when test="$DbType='Real'">number</xsl:when>
	<xsl:when test="$DbType='TinyInt'">number</xsl:when>
	<xsl:when test="$DbType='SmallInt'">number</xsl:when>
	<xsl:when test="$DbType='Binary'">bytes</xsl:when>
	<xsl:when test="$DbType='Timestamp'">bytes</xsl:when>
	<xsl:when test="$DbType='VarBinary'">bytes</xsl:when>
	<xsl:when test="$DbType='Image'">bytes</xsl:when>
	<xsl:when test="$DbType='Variant'">bytes</xsl:when>
	<xsl:when test="$DbType='Char'">string</xsl:when>
	<xsl:when test="$DbType='NChar'">string</xsl:when>
	<xsl:when test="$DbType='NText'">string</xsl:when>
	<xsl:when test="$DbType='NVarChar'">string</xsl:when>
	<xsl:when test="$DbType='Text'">string</xsl:when>
	<xsl:when test="$DbType='VarChar'">string</xsl:when>
	<xsl:when test="$DbType='Xml'">string</xsl:when>
	<xsl:when test="$DbType='UniqueIdentifier'">string</xsl:when>
	<xsl:when test="$DbType='Bit'">bool</xsl:when>
	<xsl:when test="$DbType='DateTime'">date</xsl:when>
	<xsl:when test="$DbType='Decimal'">decimal</xsl:when>
	<xsl:when test="$DbType='Float'">decimal</xsl:when>
	<xsl:when test="$DbType='Money'">decimal</xsl:when>
	<xsl:when test="$DbType='SmallMoney'">decimal</xsl:when>
	<xsl:otherwise><xsl:value-of select="$DbType" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:if test="$ColumnShow!='Hide'"> <!-- 隐藏列不用产生 -->
<xsl:if test="$IsKey!='true'"> <!-- 主键列不用产生 -->
<xsl:if test="$IsAssociation!='true'"> <!-- 子表关联列不用产生 -->
<xsl:if test="$DataType!='bytes'"> <!-- bytes类型不用产生 -->

	<!-- 根据ColumnShow决定列的显示模式 -->
	<xsl:variable name="ShowInfo" >
		<xsl:if test="$ColumnShow='HideInBox'"> Visible="false" </xsl:if>
	</xsl:variable>
	<xsl:if test="$IsForigenKey!='true'">
	<xsl:if test="$IsEnum!='true'">
		<xsl:variable name="ColumnType" >
		<xsl:choose>
			<xsl:when test="$DataType='number'">GridViewDataSpinEditColumn</xsl:when>
			<xsl:when test="$DataType='string'">GridViewDataTextColumn</xsl:when>
			<xsl:when test="$DataType='bool'">GridViewDataCheckColumn</xsl:when>
			<xsl:when test="$DataType='date'">GridViewDataDateColumn</xsl:when>
			<xsl:when test="$DataType='decimal'">GridViewDataSpinEditColumn PropertiesSpinEdit-NumberType="Float" PropertiesSpinEdit-DisplayFormatString="f" </xsl:when>
			<xsl:otherwise>GridViewDataColumn</xsl:otherwise>
		</xsl:choose>
		</xsl:variable>
		&lt;dxwgv:<xsl:value-of select="$ColumnType" /> FieldName="<xsl:value-of select="$FieldName" />" <xsl:value-of select="$ShowInfo" /> /&gt;
	</xsl:if>
	</xsl:if>
	
	<!-- 产生外键的显示模式 -->
	<xsl:if test="$IsForigenKey='true'">
		<dxwgv:GridViewDataComboBoxColumn FieldName="{$FieldName}ID" >
            <PropertiesComboBox DataSourceID="ds{$MasterTable}" EnableIncrementalFiltering="True" TextField="Name" ValueField="{$MasterField}" ValueType="System.String">
            </PropertiesComboBox>
        </dxwgv:GridViewDataComboBoxColumn>
	</xsl:if>
	
	<!-- 产生枚举的显示模式 -->
	<xsl:if test="$IsEnum='true'">
		<dxwgv:GridViewDataComboBoxColumn FieldName="{$FieldName}" >
            <PropertiesComboBox DataSourceID="dsEnum{$EnumType}" EnableIncrementalFiltering="True" TextField="Name" ValueField="ID" ValueType="System.String" />
        </dxwgv:GridViewDataComboBoxColumn>
    </xsl:if>
    
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:if>
</xsl:template>

<!-- 产生外键字段数据源 -->
<xsl:template name="CreateDataSource">

<xsl:variable name="IsForigenKey" select="IsForigenKey"></xsl:variable>
<xsl:variable name="MasterTable" select="MasterTable"></xsl:variable>
<xsl:variable name="BllNameSpace" select="/EntityMeta/GenConfig/BllConfig/Namespace"></xsl:variable>
<xsl:variable name="MdlNameSpace" select="/EntityMeta/GenConfig/MdlConfig/Namespace"></xsl:variable>
<xsl:variable name="EnumType" select="EnumType"></xsl:variable>

<xsl:if test="$IsForigenKey='true'">
    <asp:ObjectDataSource ID="ds{$MasterTable}" runat="server" DataObjectTypeName="{$MdlNameSpace}.{$MasterTable}_MDL"
        OnObjectCreating="ds{$MasterTable}_ObjectCreating" SelectMethod="Select" TypeName="{$BllNameSpace}.{$MasterTable}_BLL">
    </asp:ObjectDataSource>
</xsl:if>

<xsl:if test="IsEnum='true'">
	<asp:ObjectDataSource ID="dsEnum{$EnumType}" runat="server" DataObjectTypeName="{$EnumType}"
            OnObjectCreating="ds_Enum{$EnumType}Creating" SelectMethod="Select"
            TypeName="OT.Common.Generic.EnumDataSource">
    </asp:ObjectDataSource> 
</xsl:if>

</xsl:template>

<!-- 产生使用的控件引用 -->
<xsl:template name="UseControls">
<xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Src="../UseControl/PageCommon.ascx" TagName="PageCommon" TagPrefix="uc1" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.ASPxTreeList.v8.1" Namespace="DevExpress.Web.ASPxTreeList" TagPrefix="dxwtl" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.1.Export, Version=8.1.1.0, Culture=neutral, PublicKeyToken=49D90C14D24271B5" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dxwgv" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.1.0, Culture=neutral, PublicKeyToken=49D90C14D24271B5" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dxcp" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.v8.1, Version=8.1.1.0, Culture=neutral, PublicKeyToken=49D90C14D24271B5" Namespace="DevExpress.Web.ASPxPanel" TagPrefix="dxp" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.1, Version=8.1.1.0, Culture=neutral, PublicKeyToken=49D90C14D24271B5"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text><xsl:text>
</xsl:text>
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.1, Version=8.1.1.0, Culture=neutral, PublicKeyToken=49D90C14D24271B5"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
<xsl:text>

</xsl:text>
</xsl:template>

</xsl:stylesheet>
